package com.lightsaber.trade.as.ws.interceptor;

import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CxfInterceptor extends AbstractPhaseInterceptor<Message> {

    final static Logger LOG = LoggerFactory.getLogger(CxfInterceptor.class);

    public CxfInterceptor(String phase) {
        super(phase);
    }

    public CxfInterceptor() {
        super(Phase.RECEIVE);
    }

    @SuppressWarnings("static-access")
    public void handleMessage(Message msg) throws Fault {
        String uri = String.valueOf(msg.get(msg.REQUEST_URI));
        
        StringBuffer bf = new StringBuffer(uri + ".xml");
        msg.put(msg.REQUEST_URI, String.valueOf(bf));
        
        LOG.info((String)msg.get(msg.REQUEST_URI));
    }

    @Override
    public void handleFault(Message msg) {
        super.handleFault(msg);
        LOG.info("message={}", msg.toString());
    }

}
